package edu.mapi.ir.controllers;

import edu.mapi.ir.state.EstimatedState;
/**
 * @author ZP
 */
public class SequenceController extends AbstractController {

	protected AbstractController[] controllers;
	protected int index = 0;
	
	public SequenceController() {
		this.controllers = new AbstractController[]{};
	}
	
	public Actuation decide(Actuation lastActuation, EstimatedState state) {
		if (index >= controllers.length) {
			setComplete(true);
			return new Actuation(0,0);
		}
		if (controllers[index].isComplete()) {
			index++;
			return new StopController().decide(lastActuation, state);
		}
		//System.out.println("Active controller is "+controllers[index].getName());
		
		return controllers[index].decide(lastActuation, state);
	}

	public AbstractController[] getControllers() {
		return controllers;
	}

	public void setControllers(AbstractController[] controllers) {
		this.controllers = controllers;
	}	
}
